import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;//不初始化，默认为0   可以代表下标

    private static final int DEFAULT_CAPACITY = 10;

    public MyStack() {
        this.elem = new int[DEFAULT_CAPACITY];
    }

    public void push(int val) {
        if(isFull()) {
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize] = val;
        this.usedSize++;
    }
    public boolean isFull() {
        return this.usedSize == this.elem.length;
    }

    public int pop() {
        if(isEmpty()) {
            throw new EmptyException();
        }
        int oldVal = elem[usedSize-1];
        this.usedSize--;
        return oldVal;
    }

    public int peek() {
        if(isEmpty()) {
            throw new EmptyException();
        }
        return elem[usedSize-1];
    }

    public boolean isEmpty() {
        return this.usedSize == 0;
    }
}
